<template>
  <PiTable
    border
    isSearch
    rowKey="number"
    :tableData
    :tableColumns
    :pagination="page"
    @pageChange="pageChange"
    @radioChange="radioChange"
    @confirmSetting="getData"
  >
    <template #name="{ row }">
      <el-link type="primary" @click="download(row)">{{ row.name }}</el-link>
    </template>
    <template #createTime="{ row }">
      {{ row.createTime && $timeFormat(new Date(row.createTime), 'YYYY-MM-DD HH:mm:ss') }}
    </template>
    <template #handle="{ row }">
      <el-space>
        <el-link type="primary" @click="changeTableData(row)">编辑</el-link>
        <el-link type="danger">删除</el-link>
      </el-space>
    </template>
  </PiTable>
</template>

<script setup name="docDetailAttachment">
const loading = ref(false);
const tableData = ref([]);
const { $timeFormat, $downloadFileByUrl } = window.$fn;
const { cadDocumentApi } = window.$api;
const route = useRoute();
const page = reactive({
  pageNum: 1, //当前页
  pageSize: 10, //每页数
  total: 0, //数据总量
});
const tableColumns = ref([
  {
    prop: 'name',
    label: '文件名',
    sortable: true,
  },
  {
    prop: 'size',
    label: '大小',
    sortable: true,
  },
  {
    prop: 'modifier',
    label: '修改者',
    sortable: true,
  },
  {
    prop: 'modifyStamp',
    label: '上次修改时间',
    sortable: true,
  },
]);
onMounted(() => {
  getData();
});
const getData = () => {
  loading.value = true;
  const params = {
    oid: route.query.oid,
    page: page.pageNum,
    range: page.pageSize,
  };
  cadDocumentApi.getWTDocSecondaryFiles(params).then((res) => {
    loading.value = false;
    if (res.success) {
      tableData.value = res.data.rows;
      page.total = res.data.total;
    }
  });
};
const download = (row) => {
  $downloadFileByUrl(row.downloadUrl, row.name);
};
const pageChange = (pageNum, pageSize) => {
  page.pageNum = pageNum;
  page.pageSize = pageSize;
  getData();
};
const radioChange = (val) => {
  console.log(val);
};
</script>

<style scoped lang="less"></style>
